import { _decorator, Camera, Component, Node, Prefab } from "cc";
import { ConnMgr } from "./game/com/ConnMgr";
import { debugMgr, DebugMgr } from "./game/com/DebugMgr";
import { ErrorMgr } from "./game/com/ErrorMgr";
import { EventMgr } from "./game/com/EventMgr";
import { KeyMgr } from "./game/com/KeyMgr";
import { LayerMgr } from "./game/com/LayerMgr";
import { loadMgr, LoadMgr } from "./game/com/LoadMgr";
import { ModMgr } from "./game/com/ModMgr";
import { PopupMgr } from "./game/com/PopupMgr";
import { TimerMgr, timerMgr } from "./game/com/TimerMgr";
const { ccclass, property } = _decorator;

/**
 * 游戏全局 (入口)
 */
export const gameMain = _ as GameMain;
@ccclass("GameMain")
export class GameMain extends Component {

    @property(Camera)
    mapCam: Camera;
    @property(Camera)
    uiCam: Camera;
    @property(Node)
    mapLayers: Node;
    @property(Node)
    viewLayers: Node;
    @property(Prefab)
    playerPrefab: Prefab;

    focus: Node;

    start() {
        (gameMain as any) = this;
        new DebugMgr().init();
        new ErrorMgr().init();
        new TimerMgr().init();
        new LoadMgr().init();
        new EventMgr().init();
        new ConnMgr().init();
        new LayerMgr().init();
        new PopupMgr().init();
        new ModMgr().init();
        new KeyMgr().init();
        loadMgr.loadFirst();
        debugMgr.moduleGlobal();
    }

    update(dt: number) {

    }

    lateUpdate(dt: number) {
        if (this.focus && this.focus.active) {
            this.mapCam.node.setWorldPosition(this.focus.worldPosition);
        }
        timerMgr.onUpdate();
    }
}